[<<Previous Entry]
[^^Up^^]
[Next Entry>>]
[Menu]
[About The Guide]
Simple demo for working with objects:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//class definition example:
//----------------------------------------
class Loc //class Loc (location)
export: //instances and methods visible in child classes
//and also in class Loc object
var Row //Row element
var Col //Column element
method New=LocNew //call o:New() instances initialisation
method Get=LocGet //call o:Get() storing the position
method Set=LocSet //call o:Set() reseting the stored position
endclass
constructor LocNew() no parent //preprocessor compile see Object.ch
::Row:=0
::Col:=0
return(self) //returns self (object)
method function LocGet() //can be rewritten in "child" classes
::Row:=Row() //stored the row
::Col:=Col() //stored the column
return(nil)
method function LocSet() //can be rewritten in "child" classes
SetPos(::Row,::Col) //restore the position
return(nil)
//...................................................................
class Cursor from Loc //class cursor herited all features of class Loc
export: //and has new variable
var Size //size and methods
method New=CursorNew //instances initilisation
method Get=CursorGet //o:Get() modify Loc:Get() in sense of
// store the size of cursor too
method Set=CursorSet //o:Set() reset the stored cursor
endclass
constructor ScreenNew() //instances of class Cursor are initialised
::Size:=SC_NONE //(i.e. Size, Row, Col)
return(self) //returns self (object)
method function CursorGet() //can be rewritten in "child" classes
::parent:Get() //store Row,Col (use the herited method)
::Size:=SetCursor() //store the cursor size
return(nil)
method function CursorSet() //can be rewritten in "child" classes
::parent:Set() //store Row, Col (use herited instance)
SetCursor(::Size) //restore the cursor
return(nil)
//.....................................................................
class Screen from Cursor //the class screen herited the cursor features
export: //and adds the items
var Screen //screen_buffer
var Color //clipper color definition
//and the methods
method New=ScreenNew //o:New() initial instances set
method Get=ScreenGet //o:Get() modify Cursor:Get() to store the screen
method Set=ScreenSet //o:Set() restore the saved screeen
endclass
constructor ScreenNew() //class Screen instances are modified
::Screen:="" //(i.e. Screen, Color, Size, Row, Col)
::Color:=""
return(self) //returns self (object)
method function ScreenGet() //can be rewritten in "child" classes
::parent:Get() //store the cursor
::Color:=SetColor() //store the colors
::Screen:=SaveScreen(0,0,MaxRow(),MaxCol()) //store the screen
return(nil)
method function ScreenSet() //can be rewritten in "child" classes
::parent:Set() //restore the cursor
SetColor(::Color) //restore the colors
RestScreen(0,0,MaxRow(),MaxCol(),::Screen) //restore the screen
return(nil)
//defined classes using demo:
//---------------------------
function OurFunction()
local object Cursor of Cursor //create local object Cursor of class Cursor
local object Obr1 of Screen //create local object Obr1 of class Screen
local object Obr2 of Screen //...
Cursor:Get() //store the current cursor location
InaProcedura("Change cursor") //cursor change
Cursor:Set() //resture the cursor size and location
Obr1:Get() //store the whole screen
InaProcedura("Change screen") //screen change
Obr2:Get() //store the changed screen
repeat //repeat to until
PauseKey(0) //wait for keypressing (SetKey() processed)
Swap(Obr1,Obr2) //swap of variables
Obr2:Set() //show the screen (two screens swapping)
until LastKey()==K_ESC //ends when pressing ESC
return(nil)
WARNING!
If you use the Class(y), the each class description must be in another file.
See Also:
Meaning of the words
Syntax
System anomal behavior
This page created by ng2html v1.05, the Norton guide to HTML conversion utility.
Written by Dave Pearson